import store from '../store/index'
import { ProjectConfig } from "@/config";

export function initStore() {

  const lastLoginTime = localStorage.getItem(ProjectConfig.LAST_LOGIN_TIME);
  if(lastLoginTime){
    const currentTime = parseInt((new Date().getTime()/1000).toFixed(0));
    const isLogin = (currentTime -  parseInt(lastLoginTime)) < ProjectConfig.LOGIN_OVERTIME;
    if (isLogin) {
      const sessionUser = JSON.parse(localStorage.getItem(ProjectConfig.SESSION_USER)||'');
      if (sessionUser) {
        store.commit('setUser', sessionUser);
      }
    }else{
      sessionStorage.removeItem(ProjectConfig.SESSION_USER);
    }
  }
}
